package com.tcp2.frame.taxi;

import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

/**
 * Author: <张锦煌>
 * Time: 2015-09-23 14:01
 * Copyright (C) 2015 Xiamen Yaxon Networks CO.,LTD.
 */
public class Frame0B10 {
    private JPanel jPanel;
    public JComboBox combo0;
    public JComboBox combo1;
    public JComboBox combo2;
    public JComboBox combo3;

    public JTextField f2;
    public JTextField f3;
    public JTextField jd1;
    public JTextField jd2;

    public Frame0B10(JPanel jPanel){
        this.jPanel=jPanel;
    }

    public void init(){
        final CardLayout card1=new CardLayout();
        JPanel jp1=new JPanel();
        TitledBorder t1=new TitledBorder("外围设备上行透传");
        jp1.setBorder(t1);
        JLabel jl1 = new JLabel("功能描述：外围设备上行透传，消息ID=0x0B10                  ");
        JLabel l1=new JLabel("设备类型:   ");
        JLabel l2=new JLabel("厂商标识:   ");
        JLabel l3=new JLabel("命令类型:   ");
        String[] s12={"0x02:计价器锁车","0x12:DVR状态上报"};
        ComboBoxModel mode3=new AModel(s12);
        combo3=new JComboBox(mode3);
        final JLabel l4=new JLabel("计价器状态:     ");
        String[] s0={"0x00:锁定状态","0x01:解锁状态"};
        ComboBoxModel mode0=new AModel(s0);
        combo0=new JComboBox(mode0);
        f2=new JTextField("01");
        f3=new JTextField("0001");
        JLabel l5=new JLabel("DVR状态:");
        String[] dvr={"0x01:SD卡状态","0x02:硬盘状态","0x03:摄像头状态","0x04:麦克风状态","0x05:AD芯片状态","0x06:录像状态","0x07:录音状态","0x08:网络状态"};
        ComboBoxModel mode1=new AModel(dvr);
        combo1=new JComboBox(mode1);
        final String[] s1={"0x01:存在,可读写","0x02:存在,不可读写","0x03:不存在"};
        final String[] s2={"0x01:正常","0x02:检测到,被挡住","0x03:未检测到摄像头"};
        final String[] s3={"0x00:检测到","0x01:未检测到"};
        final String[] s4={"0x01:正常","0x02:寄存器不正常,CPU正常","0x03:寄存器正常,CPU不正常","0x04:其他异常"};
        final String[] s5={"0x00:未录像","0x01:录像中"};
        final String[] s6={"0x00:未录音","0x01:录音中"};
        final String[] s7={"0x01:3G","0x02:2G","0x03:无网络"};
        ComboBoxModel mode2=new AModel(s1);
        combo2=new JComboBox(mode2);
        Box b1=Box.createHorizontalBox();
        b1.add(l1);b1.add(combo3);b1.add(Box.createHorizontalStrut(200));
        Box b2=Box.createHorizontalBox();
        b2.add(l2);b2.add(f2);b2.add(Box.createHorizontalStrut(200));
        Box b3=Box.createHorizontalBox();
        b3.add(l3);b3.add(f3);b3.add(Box.createHorizontalStrut(200));
        final JPanel ss=new JPanel();
        TitledBorder ts1=new TitledBorder("类型");
        ss.setBorder(ts1);
        ss.setLayout(card1);
        Box b4=Box.createHorizontalBox();
        b4.add(l4);b4.add(combo0);b4.add(Box.createHorizontalStrut(200));
        ss.add(b4,"s1");
        Box h=Box.createHorizontalBox();
        h.add(l5);h.add(Box.createHorizontalStrut(10));
        h.add(combo1);h.add(Box.createHorizontalStrut(10));
        h.add(combo2);
        final Box v=Box.createVerticalBox();
        v.add(h);v.add(Box.createVerticalStrut(10));
        ss.add(v,"s2");
        final Box vb=Box.createVerticalBox();
        vb.add(b1);vb.add(Box.createVerticalStrut(10));
        vb.add(b2);vb.add(Box.createVerticalStrut(10));
        vb.add(b3);vb.add(Box.createVerticalStrut(10));
        card1.show(ss,"s1");
        vb.add(ss);
        combo3.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                String event= (String) e.getItem();
                switch (event){
                    case "0x02:计价器锁车":
                        card1.show(ss,"s1");vb.add(ss);
                        break;
                    case "0x12:DVR状态上报":
                        card1.show(ss,"s2");vb.add(ss);
                        break;
                }
            }
        });
        final Box nb1=Box.createVerticalBox();
        combo1.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                String state= (String) e.getItem();
                switch (state){
                    case "0x01:SD卡状态":
                        v.remove(nb1);combo2.removeAllItems();
                        combo2.setModel(new AModel(s1));break;
                    case "0x02:硬盘状态":
                        v.remove(nb1);combo2.removeAllItems();
                        combo2.setModel(new AModel(s1));break;
                    case "0x03:摄像头状态":
                        v.remove(nb1);combo2.removeAllItems();
                        combo2.setModel(new AModel(s2));break;
                    case "0x04:麦克风状态":
                        v.remove(nb1);combo2.removeAllItems();
                        combo2.setModel(new AModel(s3));break;
                    case "0x05:AD芯片状态":
                        v.remove(nb1);combo2.removeAllItems();
                        combo2.setModel(new AModel(s4));break;
                    case "0x06:录像状态":
                        v.remove(nb1);combo2.removeAllItems();
                        combo2.setModel(new AModel(s5));break;
                    case "0x07:录音状态":
                        v.remove(nb1);combo2.removeAllItems();
                        combo2.setModel(new AModel(s6));break;
                    case "0x08:网络状态":
                        nb1.removeAll();
                        v.remove(nb1);combo2.removeAllItems();
                        combo2.setModel(new AModel(s7));
                        JLabel jl81=new JLabel("模块类型:");
                        jd1=new JTextField("01");
                        JLabel jl83=new JLabel("信号强度:");
                        jd2=new JTextField("88");
                        Box n1=Box.createHorizontalBox();
                        n1.add(jl81);n1.add(jd1);n1.add(Box.createHorizontalStrut(10));
                        n1.add(jl83);n1.add(jd2);
                        nb1.add(n1);nb1.add(Box.createVerticalStrut(10));
                        v.add(nb1);break;
                    default:break;
                }

            }
        });
        vb.add(Box.createVerticalStrut(10));
        jp1.add(vb);
        Box vBox=Box.createVerticalBox();
        vBox.add(jl1);
        vBox.add(Box.createVerticalStrut(30));
        vBox.add(jp1);
        jPanel.add(vBox, "p3");
    }
    class AModel extends DefaultComboBoxModel{

        AModel(String[] s){

            for(int i=0;i<s.length;i++){
                addElement(s[i]);
            }
        }
    }

}
